﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class PayBackItem : IAccessible<P_PayBackItem, PayBackItem>, ILogicEntity<P_PayBackItem, PayBackItem>
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public int PayBackId { get; set; }
        public string PayBackUser { get; set; }
        public int CycleNumber { get; set; }
        public DateTime PayBackDate { get; set; }
        public decimal PayBackInterest { get; set; }
        public decimal PayBackPrincipal { get; set; }
        public decimal PayBackRemain { get; set; }
        public RepaymentStatus Status { get; set; }
        public DateTime PayBackTime { get; set; }
        public int PolicyId { get; set; }
        public int ProjectId { get; set; }

        public string ProductName { get; set; }
        public string ProjectTitle { get; set; }
        public string ProjectCode { get; set; }

        protected override void Covariant(P_PayBackItem model)
        {
            if (model != null)
            {
                this.CycleNumber = model.CycleNumber;
                this.ID = model.ID;
                this.PayBackDate = model.PayBackDate;
                this.PayBackId = model.PayBackID;
                this.PayBackInterest = model.PayBackInterest;
                this.PayBackPrincipal = model.PayBackPrincipal;
                this.PayBackTime = model.PayBackTime;
                this.PayBackUser = model.PayBackUser;
                this.Status = (RepaymentStatus)model.Status;
                this.UserName = model.UserName;
                this.PayBackRemain = model.PayBackRemain;
                this.PolicyId = model.PolicyId;
                this.ProjectId = model.ProjectId;
            }
        }

        protected override P_PayBackItem Inverter(PayBackItem model)
        {
            if (model != null)
            {
                return new P_PayBackItem()
                {
                    CycleNumber = model.CycleNumber,
                    ID = model.ID,
                    PayBackDate = model.PayBackDate,
                    PayBackID = (int)model.PayBackId,
                    PayBackInterest = model.PayBackInterest,
                    PayBackPrincipal = model.PayBackPrincipal,
                    PayBackTime = model.PayBackTime,
                    PayBackUser = model.PayBackUser,
                    Status = (int)model.Status,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public PayBackItem Set(P_PayBackItem dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
